package dao

import (
	"zhihu/model"
)

func AddArticle(id int, title string, counter string) (aretcle model.Article, err error) {
	aretcle = model.Article{
		UserId:  id,
		Title:   title,
		Counter: counter,
	}
	err = model.DB.Debug().Model(model.Article{}).Create(&aretcle).Error
	return aretcle, err
}

func ListArticle(id int, like int) (listaretcle model.Article, err error) {
	err = model.DB.Debug().Where("id=? ", like).Where("user_id=?", id).Find(&listaretcle).Error
	return listaretcle, err
}

func LikeArticle(id int, like int) (likes model.LikeArticle, err error) {
	likes = model.LikeArticle{

		UserId:    id,
		ArticleId: like,
	}
	err = model.DB.Create(&likes).Error
	return likes, err
}

func ArticleReview(id int, id2 int, context string) (articlereview model.ArticleReview, err error) {
	articlereview = model.ArticleReview{

		UserId:    id,
		ArticleId: id2,
		Context:   context,
	}
	err = model.DB.Debug().Create(&articlereview).Error
	return articlereview, err
}

func ArticleReviewfu(id int, id2 int, id3 int, context string) (articlereview model.ArticleReview, err error) {
	articlereview = model.ArticleReview{
		FatherId:  id3,
		UserId:    id,
		ArticleId: id2,
		Context:   context,
	}
	err = model.DB.Debug().Create(&articlereview).Error
	return articlereview, err
}

func ArticleReviewLike(id int, id2 int) (likes model.ArticleHistory, err error) {
	likes = model.ArticleHistory{
		UserId:    id,
		ArticleId: id2,
	}
	err = model.DB.Create(&likes).Error
	return likes, err
}

func ListArticleReviewLike(id int, id2 int) (articleList []model.ArticleReview, err error) {
	err = model.DB.Model(&model.ArticleReview{}).Where("user_id=?", id).Where("article_id =?", id2).Find(&articleList).Error
	return articleList, err
}
